import java.sql.*;
import java.io.*;
public class InsertFile
{
    public static void main(String args[])
    {
        try{
            Class.forName("org.postgresql.Driver");
            String url="jdbc:postgresql://host:dbport/dbname";
            Connection cn=DriverManager.getConnection(url,"username","password");
            String sql = "insert into table_name (column) values(?)";
            PreparedStatement statement=cn.prepareStatement(sql);
            FileInputStream inputStream=new FileInputStream("file_path");
            statement.setBinaryStream(1,inputStream,inputStream.available());
            statement.execute();
            System.out.println("Insert Success");
            inputStream.close();
            statement.close();
            cn.close();
        }catch(Exception e){System.out.println(e.getMessage());}
    }
}
